//Javascript functions
$(document).ready(function(){
    //para votar en la encuesta
    $("#laEncuestaSubmit").click(function(){
        var op = $("input[name='optionRespuesta']:checked").val();
        var eid = $("#encuestaID").val();

        $.ajax({
            type: "GET",
            url: "/votaEncuesta.php",
            data: "op="+op+"&eid="+eid,
            cache: false,
            success: function(html){
                $(".answers").fadeOut('slow', function(){
                   $("#encuesta_results").removeClass('hidden').empty().append(html).fadeIn('slow');
                });
            }
        });
    });

    $("#postComentario").click(function(){
        var user = $("#txtCommenterName").val();
        var email = $("#txtCommenterEmail").val();
        var comment = $("#txtCommenterText").val();
        var notaid = $("#notaid").val();

        if (user != "" && email != "" && comment != ""){
            $.ajax({
               type: "POST",
                url: "/post-comments.php",
                data: "user="+user+"&email="+email+"&comment="+comment+"&notaid="+notaid,
                cache: false,
                success: function(html){
                    $("#commentsContainer").empty().fadeOut('slow').append(html).fadeIn('slow');
                }
            });
        }
    });
});